import UAParser from 'ua-parser-js'
import { useAuthStore } from '@/store'
import { isArray, isString } from '@/utils'

/** 获取设备信息 */
export function useDeviceInfo() {
    const parser = new UAParser()
    const result = parser.getResult()
    return result
}

/** 权限判断 */
export function usePermission() {
    const auth = useAuthStore()

    function hasPermission(permission: string | string[]) {
        const permissionList = auth.permissionList

        if (isArray(permission)) {
            return permission.some((item) => permissionList.has(item))
        }
        if (isString(permission)) {
            return permissionList.has(permission)
        }
    }

    return {
        hasPermission
    }
}
